<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use App\Models\ActivityType;

class ActivityProjectVideoPostRequest extends Request
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        $data = Request::all();
        if (isset($data['id'])) {
            $rules['id'] = 'required|numeric';
        }
        $rules['activity_type'] = 'required';
        $rules['activity_id'] = 'sometimes|numeric';
        if (isset($data['activity_type'])) {
            $type = ActivityType::where('code', $data['activity_type'])->first();
            (isset($type) && $type->is_roadshow == 1) && $rules['project_id'] = 'required|numeric';
        }
//        $rules['path'] = 'required|url';
//        $rules['app_path'] = 'required|url';
        $rules['subject'] = 'required';
        $rules['image'] = 'required';
//        $rules['pubdate'] = 'required|date';
        $rules['content'] = 'required';
        $rules['hot'] = 'required';
        if (!empty($data['views'])) {
            $rules['views'] = 'numeric';
        }
        if (!empty($data['likes'])) {
            $rules['likes'] = 'numeric';
        }
        if (!empty($data['click_views'])) {
            $rules['click_views'] = 'numeric';
        }
        if (!empty($data['sort'])) {
            $rules['sort'] = 'numeric';
        }

        $rules['top'] = 'required|numeric';

        return $rules;
    }

    public function attributes()
    {
        $attributes = array(
            'id'            => '视频id',
            'activity_id'   => '活动名称',
            'activity_type' => '活动类型',
            'project_id'    => '项目名称',
            'path'          => '视频地址',
            'app_path'      => 'APP视频地址',
            'subject'       => '标题',
            'image'         => '视频图片',
            'pubdate'       => '发布时间',
            'content'       => '内容',
            'views'         => '播放量',
            'likes'         => '点赞',
            'click_views'   => '点击量',
            'hot'           => '是否热门',
            'sort'          => '排序',
            'top'           => '是否置顶',
        );

//        return array();
        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required' => ':attribute为必填选项',
            'numeric'  => ':attribute必须为数字',
            'url'      => ':attribute必须为合乎规范的url地址',
            'date'     => ':attribute必须为日期',
        ];

        return $messages;
    }
}
